import { ref, reactive, onMounted } from "vue";
// 导入宠物分类列表接口
import { getCateList } from "@/api/cateAPI";

export const useCateDataList = () => {
  // 表格列的配置
  const columns = reactive([
    {
      title: "分类id",
      dataIndex: "id",
      key: "id",
    },
    {
      title: "类别",
      dataIndex: "pet_type",
      key: "pet_type",
    },
    {
      title: "操作",
      key: "operation",
      slots: { customRender: "operation" },
    },
  ]);

  // 定义分类列表
  const data = ref([]);

  // 获取分类列表数据
  const getCateData = () => {
    // 发送请求获取宠物分类列表
    getCateList()
      .then((res) => {
        data.value = res.data;
      })
      .catch((error) => {
        throw new Error(error);
      });
  };

  onMounted(() => {
    getCateData();
  });

  return {
    columns,
    data,
    getCateData,
  };
};
